package com.xiaoshuidi.cloud.module.member.controller.app.message;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.app.message.vo.MessageListVO;
import com.xiaoshuidi.cloud.module.member.controller.app.message.vo.MessagePageVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.message.MemberMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "租客APP - 消息")
@RestController
@RequestMapping(ApiConstants.NAME + "/message")
@Validated
public class AppMemeberMessageController {
    @Resource
    private MemberMessageService memberMessageService;


    @PostMapping("/get-page")
    @Operation(summary = "租客获得消息列表")
    public CommonResult<PageResult<MessageListVO>> getAppPage(@Valid @RequestBody MessagePageVO pageVO) {
        Long id = SecurityFrameworkUtils.getLoginUser().getId();
        pageVO.setUserId(id);
        PageResult<MessageListVO> pageResult = memberMessageService.getAppPage(pageVO);
        return success(pageResult);
    }

    @GetMapping("/update-status/{id}")
    @Operation(summary = "改变消息为已读")
    public CommonResult<Boolean> updateStatus(@PathVariable("id") Long id) {
        return success(memberMessageService.updateStatus(id));
    }
}
